﻿using System;
using System.Linq;
using Fetches.Fetch.Dto;
using Fetches.Fetch.Fetcher;

namespace Fetches.Custom.Legacy.V1
{
    public class Site100Xing : SiteOrder<HttpClientFetcher>
    {
        public Site100Xing()
        {
            AddSeedUrl("http://www.100xing.com/zxzx/zxcs/");
            IndexPatterns.Add(@"http://www\.100xing\.com/zxzx/zxcs/index.+html");
            ContentPatterns.Add(@"http://www\.100xing\.com/zxzx/zxcs/\d+\.html");
        }
        public override Action<ResponsePage> DefaultProcessor()
        {
            return page =>
            {
                var html = ParseHtml(page.SourceCode);
                var result = new ResultItems();
                result.Summary = html.QuerySelectorAll(".summary").First().InnerHtml;
                var content = html.QuerySelectorAll(".content").First();
                if (content != null)
                {
                    foreach (var item in content.QuerySelectorAll(".recommend"))
                    {
                        item.Remove();
                    }

                    foreach (var item in content.QuerySelectorAll("p"))
                    {
                        if (item.HasAttribute("style"))
                        {
                            item.Remove();
                        }
                    }

                    result.Content = content.InnerHtml;
                }
            };
        }
    }
}
